<template>
  <div class="knowledge-container">
    <div class="knowledge-grid">
      <el-card 
        v-for="(item, index) in cknowledges" 
        :key="index"
        class="knowledge-card"
        shadow="hover"
        @click.native="handleDetail(item)">
        
        <!-- 多媒体内容 -->
        <div class="knowledge-media">
          <video 
            v-if="item.type === 'mp4' || item.type === 'MP4'"
            class="media-content"
            controls
            :poster="getThumbnail(item)">
            <source :src="$store.state.imgShowRoad + '/file/' + item.picPath" type="video/mp4">
          </video>
          <el-image
            v-else
            class="media-content"
            :src="$store.state.imgShowRoad + '/file/' + item.picPath"
            fit="cover">
            <div slot="error" class="media-error">
              <i class="el-icon-picture-outline"></i>
            </div>
          </el-image>
        </div>

        <!-- 知识信息 -->
        <div class="knowledge-info">
          <h4 class="knowledge-title">{{ item.title }}</h4>
          <p class="knowledge-desc">{{ item.content }}</p>
          
          <div class="knowledge-author">
            <el-avatar :size="24" :src="require('../assets/img/up-user.png')"></el-avatar>
            <span class="author-name">{{ item.ownName }}</span>
          </div>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    cknowledges: {
      type: Array,
      required: true
    }
  },
  methods: {
    handleDetail(item) {
      this.$router.push(`/home/knowledge/${item.knowledgeId}`);
    },
    getThumbnail(item) {
      // 这里可以添加获取视频缩略图的逻辑
      return '';
    }
  }
};
</script>

<style lang="less" scoped>
.knowledge-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  
  .knowledge-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(450px, 1fr));
    gap: 20px;
  }
  
  .knowledge-card {
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    
    &:hover {
      transform: translateY(-5px);
      box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
      
      .knowledge-title {
        color: #67C23A;
      }
    }
    
    .knowledge-media {
      height: 200px;
      overflow: hidden;
      border-radius: 6px;
      margin-bottom: 10px;
      
      .media-content {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
      
      .media-error {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100%;
        height: 100%;
        background: #f5f7fa;
        color: #909399;
        font-size: 40px;
      }
    }
    
    .knowledge-info {
      .knowledge-title {
        margin: 0 0 10px;
        font-size: 16px;
        color: #303133;
        line-height: 1.4;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
      }
      
      .knowledge-desc {
        margin: 0 0 15px;
        color: #606266;
        font-size: 14px;
        line-height: 1.5;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 3;
        overflow: hidden;
      }
      
      .knowledge-author {
        display: flex;
        align-items: center;
        
        .author-name {
          margin-left: 8px;
          color: #909399;
          font-size: 13px;
        }
      }
    }
  }
}
</style>